import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author zhangdi
 * @version 1.0
 * @date 2022.11.4
 */
public class ForeachHashMap {
    public static void main(String[] args) {
        List<ffff> ffffList = new ArrayList<>();
        ffffList.add(new ffff(5L, "name5"));
        ffffList.add(new ffff(1L, "name1"));
        ffffList.add(new ffff(3L, "name3"));
        ffffList.add(new ffff(11L, "name11"));
        ffffList.add(new ffff(0L, "name0"));

        Map<Long, ffff> longffffMap = ffffList.stream().collect(Collectors.toMap(ffff::getId, (v) -> v));

//        Map<Long, ffff> longffffMap = new HashMap<>();
//        int c = 10;
//        for (int i = 0; i < c; i++) {
//            longffffMap.put(i + 0L, new ffff(i + 1L, "name" + i));
//        }
//
//        for (Map.Entry<Long, ffff> entry : longffffMap.entrySet()) {
//            System.out.println(entry.getKey());
//        }

        Iterator<Map.Entry<Long, ffff>> fff =  longffffMap.entrySet().iterator();
        while (fff.hasNext()) {
            System.out.println(fff.next().getKey());
        }
//        longffffMap.forEach((ki, vn) -> {
//            System.out.println(ki);
//        });
    }

    static class ffff {
        public ffff(Long id, String name) {
            this.id = id;
            this.name = name;
        }

        private Long id;
        private String name;

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
